<?php
include_once "inc/Network.php";
include_once "inc/ParamManager.php";
include_once "inc/db.php";

$server_mysql = "localhost";

db_init();
$pm = new ParamManager();

// connect to the server
$network = new Network();
$network->connect();

$count = 1;

$output = array();
$cmd = "echo \"stbd_s\",\"stbd_c\" > output.csv";
exec($cmd, $output);

// keep testing, to check for memory leaks
while($count <= 100) {
	echo "Running test #$count\n";	$count ++;

	include "tests/test.php";
	//include "tests/monitor.php";
	//include "tests/adc_daily.php";
	
	// wait for command to finish
	while($line = $network->recv()) {
		if(strpos($line, "info=2") !== false) {
			break;
		}
	}

	// delete the task now that its finished
	$network->send("cmd=task_del|id=$task_id\n");

	$used[0] = $used[1] = "";

	$output = array();
	$cmd = "tasklist /fo csv";
	exec($cmd, $output);
	foreach($output as $next) {
		$parsed = str_getcsv(
			$next, # Input line
			',',   # Delimiter
			'"',   # Enclosure
			'\\'   # Escape char
			);
//		print_r($parsed);

		if(!strcmp($parsed[0], "stbd_s.exe")) {
			$parts = explode(" ", $parsed[4]);
			$used[0] = $parts[0];
		}
		if(!strcmp($parsed[0], "stbd_c.exe")) {
			$parts = explode(" ", $parsed[4]);
			$used[1] = $parts[0];
		}
		
	}

	$cmd = "echo \"". $used[0] ."\",\"". $used[1] ."\" >> output.csv";
	exec($cmd, $output);

	// pause for a bit
//	sleep(1);
}

?>
